(* Content-type: application/vnd.wolfram.mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 11.0' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       158,          7]
NotebookDataLength[      9669,        257]
NotebookOptionsPosition[      9130,        234]
NotebookOutlinePosition[      9565,        253]
CellTagsIndexPosition[      9522,        250]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[
 StyleBox["\:6a21\:62df\:6298\:5c04", "Title"]], "Input",
 CellFrame->{{0, 0}, {0.5, 0}},
 CellGroupingRules->{"GroupTogetherGrouping", 10000.},
 CellChangeTimes->{{3.817331932618697*^9, 3.8173319460104628`*^9}, 
   3.817348546926899*^9, {3.817357762925655*^9, 3.8173577657199345`*^9}, 
   3.817521823174597*^9, 3.817616139023605*^9, 3.817618174598412*^9, 
   3.817690181898816*^9, 3.8177897710308266`*^9, {3.818310418143242*^9, 
   3.818310419912419*^9}},
 TextAlignment->Center],

Cell[BoxData[
 StyleBox["\:6298\:5c04\:7684\:8ba1\:7b97\:975e\:5e38\:590d\:6742", 
  "Subsubsection"]], "Input",
 CellChangeTimes->{{3.8183105701414404`*^9, 3.8183105806444902`*^9}},
 TextAlignment->Center],

Cell[CellGroupData[{

Cell[BoxData[{
 RowBox[{
  RowBox[{
   RowBox[{"reflectRay", "[", 
    RowBox[{"ray_", ",", "normal_"}], "]"}], ":=", 
   RowBox[{"(", "\[IndentingNewLine]", 
    RowBox[{"ray", "-", 
     RowBox[{"2", 
      RowBox[{"Dot", "[", 
       RowBox[{"ray", ",", "normal"}], "]"}], "*", "normal"}]}], 
    "\[IndentingNewLine]", ")"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"refract", "[", 
    RowBox[{"ray_", ",", "normal_", ",", "refractive_"}], "]"}], ":=", 
   RowBox[{"(", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"If", "[", 
      RowBox[{
       RowBox[{
        RowBox[{"Dot", "[", 
         RowBox[{"ray", ",", "normal"}], "]"}], ">", "0"}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"r", "=", "refractive"}], ";", 
        RowBox[{"norm", "=", 
         RowBox[{"-", "normal"}]}], ";"}], ",", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"r", "=", 
         RowBox[{"1", "/", "refractive"}]}], ";", 
        RowBox[{"norm", "=", "normal"}], ";"}]}], "]"}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"uv", "=", 
      RowBox[{"Normalize", "[", "ray", "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"dt", "=", 
      RowBox[{"Dot", "[", 
       RowBox[{"uv", ",", "norm"}], "]"}]}], ";", "\[IndentingNewLine]", 
     RowBox[{"discriminant", "=", 
      RowBox[{"1", "-", 
       RowBox[{
        SuperscriptBox["r", "2"], 
        RowBox[{"(", 
         RowBox[{"1", "-", 
          SuperscriptBox["dt", "2"]}], ")"}]}]}]}], ";", 
     "\[IndentingNewLine]", "\[IndentingNewLine]", 
     RowBox[{"If", "[", 
      RowBox[{
       RowBox[{"discriminant", ">", "0"}], ",", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"r", 
         RowBox[{"(", 
          RowBox[{"uv", "-", 
           RowBox[{"norm", " ", "dt"}]}], ")"}]}], "-", 
        RowBox[{"norm", " ", 
         SqrtBox["discriminant"]}]}], "\[IndentingNewLine]", ",", "  ", 
       "\[IndentingNewLine]", 
       RowBox[{"reflectRay", "[", 
        RowBox[{"ray", ",", "norm"}], "]"}]}], "  ", "\[IndentingNewLine]", 
      "\n", "]"}]}], "\[IndentingNewLine]", ")"}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{"Manipulate", "[", "\[IndentingNewLine]", 
  RowBox[{
   RowBox[{
    RowBox[{"rayStart", "=", "p"}], ";", "\[IndentingNewLine]", 
    RowBox[{"rayEnd", "=", 
     RowBox[{"{", 
      RowBox[{"0", ",", "0"}], "}"}]}], ";", "\[IndentingNewLine]", 
    RowBox[{"normalStart", "=", 
     RowBox[{"{", 
      RowBox[{"0", ",", "0"}], "}"}]}], ";", "\[IndentingNewLine]", 
    RowBox[{"normalEnd", "=", 
     RowBox[{"{", 
      RowBox[{"0", ",", "1"}], "}"}]}], ";", "\[IndentingNewLine]", 
    RowBox[{"v", "=", 
     RowBox[{"rayEnd", "-", "rayStart"}]}], ";", "\[IndentingNewLine]", 
    RowBox[{"nor", "=", 
     RowBox[{"normalEnd", "-", "normalStart"}]}], ";", "\[IndentingNewLine]", 
    RowBox[{"reflected", "=", 
     RowBox[{"refract", "[", 
      RowBox[{"v", ",", "nor", ",", "r"}], "]"}]}], ";", 
    "\[IndentingNewLine]", 
    RowBox[{"Graphics", "[", 
     RowBox[{
      RowBox[{"{", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"Arrow", "[", 
         RowBox[{"{", 
          RowBox[{"rayStart", ",", "rayEnd"}], "}"}], "]"}], ",", 
        "\[IndentingNewLine]", 
        RowBox[{"Arrow", "[", 
         RowBox[{"{", 
          RowBox[{"normalStart", ",", "normalEnd"}], "}"}], "]"}], ",", 
        "\[IndentingNewLine]", 
        RowBox[{"Arrow", "[", 
         RowBox[{"{", 
          RowBox[{"normalStart", ",", "reflected"}], "}"}], "]"}], ",", 
        "\[IndentingNewLine]", 
        RowBox[{"Style", "[", 
         RowBox[{
          RowBox[{"{", 
           RowBox[{
            RowBox[{"Opacity", "[", "0.5", "]"}], ",", 
            RowBox[{"HalfPlane", "[", 
             RowBox[{
              RowBox[{"{", 
               RowBox[{
                RowBox[{"{", 
                 RowBox[{"0", ",", "0"}], "}"}], ",", 
                RowBox[{"{", 
                 RowBox[{"1", ",", "0"}], "}"}]}], "}"}], ",", 
              RowBox[{"{", 
               RowBox[{"0", ",", 
                RowBox[{"-", "1"}]}], "}"}]}], "]"}]}], "}"}], ",", 
          "LightBlue"}], "]"}]}], "}"}], ",", "\[IndentingNewLine]", 
      RowBox[{"Axes", "\[Rule]", "True"}], ",", 
      RowBox[{"PlotRange", "\[Rule]", 
       RowBox[{"{", 
        RowBox[{
         RowBox[{"{", 
          RowBox[{
           RowBox[{"-", "1"}], ",", "1"}], "}"}], ",", 
         RowBox[{"{", 
          RowBox[{
           RowBox[{"-", "1"}], ",", "1"}], "}"}]}], "\[IndentingNewLine]", 
        "}"}]}]}], "]"}]}], ",", "\[IndentingNewLine]", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{"p", ",", 
       RowBox[{"{", 
        RowBox[{
         RowBox[{"-", "1"}], ",", "1"}], "}"}]}], "}"}], ",", "Locator"}], 
    "}"}], ",", 
   RowBox[{"{", 
    RowBox[{"r", ",", "1", ",", "2"}], "}"}]}], "\[IndentingNewLine]", 
  "]"}]}], "Input",
 CellChangeTimes->{{3.8183104571421413`*^9, 3.8183104575731845`*^9}, {
  3.819086032706518*^9, 3.8190860335115986`*^9}, {3.8206307670939727`*^9, 
  3.8206308000962725`*^9}, {3.8206308746447268`*^9, 3.8206308764449067`*^9}}],

Cell[BoxData[
 TagBox[
  StyleBox[
   DynamicModuleBox[{$CellContext`p$$ = {-0.636, 
    0.6540000000000001}, $CellContext`r$$ = 1.389, Typeset`show$$ = True, 
    Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", 
    Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = 
    "\"\:65e0\:6807\:9898\"", Typeset`specs$$ = {{{
       Hold[$CellContext`p$$], {-1, 1}}, Automatic}, {
      Hold[$CellContext`r$$], 1, 2}}, Typeset`size$$ = {468., {227., 235.}}, 
    Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = 
    True, $CellContext`r$313$$ = 0}, 
    DynamicBox[Manipulate`ManipulateBoxes[
     1, StandardForm, 
      "Variables" :> {$CellContext`p$$ = {-1, 1}, $CellContext`r$$ = 1}, 
      "ControllerVariables" :> {
        Hold[$CellContext`r$$, $CellContext`r$313$$, 0]}, 
      "OtherVariables" :> {
       Typeset`show$$, Typeset`bookmarkList$$, Typeset`bookmarkMode$$, 
        Typeset`animator$$, Typeset`animvar$$, Typeset`name$$, 
        Typeset`specs$$, Typeset`size$$, Typeset`update$$, Typeset`initDone$$,
         Typeset`skipInitDone$$}, 
      "Body" :> ($CellContext`rayStart = $CellContext`p$$; \
$CellContext`rayEnd = {0, 0}; $CellContext`normalStart = {0, 
         0}; $CellContext`normalEnd = {0, 
         1}; $CellContext`v = $CellContext`rayEnd - $CellContext`rayStart; \
$CellContext`nor = $CellContext`normalEnd - $CellContext`normalStart; \
$CellContext`reflected = $CellContext`refract[$CellContext`v, \
$CellContext`nor, $CellContext`r$$]; Graphics[{
          Arrow[{$CellContext`rayStart, $CellContext`rayEnd}], 
          Arrow[{$CellContext`normalStart, $CellContext`normalEnd}], 
          Arrow[{$CellContext`normalStart, $CellContext`reflected}], 
          Style[{
            Opacity[0.5], 
            HalfPlane[{{0, 0}, {1, 0}}, {0, -1}]}, LightBlue]}, Axes -> True, 
         PlotRange -> {{-1, 1}, {-1, 1}}]), 
      "Specifications" :> {{{$CellContext`p$$, {-1, 1}}, Automatic, 
         ControlType -> Locator}, {$CellContext`r$$, 1, 2}}, "Options" :> {}, 
      "DefaultOptions" :> {}],
     ImageSizeCache->{539., {286., 295.}},
     SingleEvaluation->True],
    Deinitialization:>None,
    DynamicModuleValues:>{},
    SynchronousInitialization->True,
    UndoTrackedVariables:>{Typeset`show$$, Typeset`bookmarkMode$$},
    UnsavedVariables:>{Typeset`initDone$$},
    UntrackedVariables:>{Typeset`size$$}], "Manipulate",
   Deployed->True,
   StripOnInput->False],
  Manipulate`InterpretManipulate[1]]], "Output",
 CellChangeTimes->{
  3.8183104605714846`*^9, {3.819085970945342*^9, 3.819085992760524*^9}, 
   3.819086034807728*^9, 3.820630807679031*^9, 3.820630879806243*^9}]
}, Open  ]]
},
WindowToolbars->"EditBar",
WindowSize->{784, 810},
WindowMargins->{{Automatic, 17}, {Automatic, 0}},
CellContext->Notebook,
Magnification:>1.3 Inherited,
FrontEndVersion->"11.0 for Microsoft Windows (64-bit) (2016\:5e7410\:67088\
\:65e5)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[558, 20, 494, 9, 96, "Input",
 CellGroupingRules->{"GroupTogetherGrouping", 10000.}],
Cell[1055, 31, 206, 4, 49, "Input"],
Cell[CellGroupData[{
Cell[1286, 39, 5158, 138, 1285, "Input"],
Cell[6447, 179, 2667, 52, 634, "Output"]
}, Open  ]]
}
]
*)

